package com.stlm2.controller;


import com.stlm2.dems.card.service.CardService;
import com.stlm2.dems.service.TiXianShenQingService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ZLQ on 2017/6/14.
 */
@Controller
@RequestMapping("/tiXianC")
public class TiXianController {
    @Resource
    private TiXianShenQingService tiXianShenQingService;

    @Resource
    private CardService cardService;


    /*
*ZLQ
*前台用户获取资金的兑换记录列表
* token:用户token
* page:页码
 */
    @ResponseBody
    @RequestMapping(value="/userGetTiXianShenQingList.json",produces="application/json;charset=UTF-8")
    public  String userGetTiXianShenQingList(String companyCode,ModelMap model,String token,String page){
        String data=null;
        try {
            data=tiXianShenQingService.userGetTiXianShenQingList( model, token, page);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"获取记录列表失败",data);
        }
        return  data;
    }
    /*
*ZLQ
*前台用户获取资金的兑换记录详情
* token:用户token
* page:页码
*/
    @ResponseBody
    @RequestMapping(value="/userGetTiXianShenQingDetails.json",produces="application/json;charset=UTF-8")
    public  String userGetTiXianShenQingDetails(String companyCode,ModelMap model,String token,String id){
        String data=null;
        try {
            data=tiXianShenQingService.userGetTiXianShenQingDetails( model, token, id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"获取记录详情失败",data);
        }
        return  data;
    }

    /*
    *ZLQ
    *前台用户添加提现申请
    * token：
    * money：金额
    * password：交易密码
    * accountName：银行卡户名
    * bank:开户银行
    * cardNum：银行卡卡号
    * factorage:手续费
    * kaihuhang:开户行
    * cardId:银行卡ID
    *
     */
    @ResponseBody
    @RequestMapping(value="/addTiXianShenQing.json",produces="application/json;charset=UTF-8")
    public  String addTiXianShenQing(String companyCode,ModelMap model,String token,String money,String password,String accountName,String bankId,
                                     String cardNum,String factorage,String kaihuhang,String cardId){
        String data=null;
        try {
            data=tiXianShenQingService.addTiXianShenQing(model,token,money,password,factorage,cardId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"提现失败",data);
        }
        return  data;

    }

    /*
使用银行卡
 */
    @ResponseBody
    @RequestMapping(value="/employCard.json",produces="application/json;charset=UTF-8")
    public String employCard(String companyCode,ModelMap model, String token, HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        String date;
        try {
            date= cardService.employCard(token);
        }catch (Exception e){
            e.getStackTrace();
            return CodeContent.getModelByCode(0,"获取银行卡信息失败", model);
        }
        return date;
    }

    /*
*ZLQ
*获取提现手续费
*
 */
    @ResponseBody
    @RequestMapping(value="/getTiXianFactorage.json",produces="application/json;charset=UTF-8")
    public  String getTiXianFactorage(String companyCode,ModelMap model){
        String data=null;
        try {
            data=tiXianShenQingService.getTiXianFactorage(model);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"获取手续费失败",data);
        }
        return  data;
    }


}
